<template>
  <div class="search">
    <div class="search-back" @click="back">
      <em class="iconfont">&#xe7e0;</em>
    </div>
    <div class="search-box">
      <span class="search-icon">
    <em class="iconfont">&#xe617;</em>
      </span>
      <input type="text" class="search-input" placeholder="请输入商品名称">
    </div>
  </div>
  <div class="wrapper">
    <ShopInfo :item="item" :hidden-bordered="true" />
  </div>
  <ShopContent :shop-name="item.name"/>
  <Cart />
</template>

<script>
import ShopInfo from '@/components/ShopInfo'
import { useRoute, useRouter } from 'vue-router'
import { reactive, toRefs } from 'vue'
import * as request from '@/utils/request'
import ShopContent from '@/views/shop/ShopContent'
import Cart from '@/views/shop/Cart'

const useShopInfoEffect = () => {
  const route = useRoute()
  const data = reactive({ item: {} })
  const getItemData = async () => {
    const result = await request.get(`/api/shop/${route.params.id}`)
    data.item = result.data
  }
  const { item } = toRefs(data)
  return {
    item,
    getItemData
  }
}
const useHandleBackClickEffect = () => {
  const router = useRouter()
  const back = () => {
    router.back()
  }
  return { back }
}
export default {
  name: 'Shop',
  components: {
    ShopContent,
    ShopInfo,
    Cart
  },
  setup () {
    const {
      item,
      getItemData
    } = useShopInfoEffect()
    const { back } = useHandleBackClickEffect()
    getItemData()
    return {
      item,
      back
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  padding: 0 .18rem;
}

.search {
  height: .32rem;
  width: 90%;
  display: flex;
  align-items: center;
  vertical-align: center;
  margin-top: .16rem;

  .search-back {
    margin: 0 .16rem;

    .iconfont {
      color: #B6B6B6;
      font-size: .22rem;
    }
  }

  .search-box {
    height: .32rem;
    width: 3rem;
    background: #F5F5F5;
    border-radius: .16rem;
    display: flex;
    align-items: center;
    vertical-align: center;

    .search-icon {
      margin: 0 .12rem 0 .16rem;

      .iconfont {
        color: #B7B7B7;
        font-size: .20rem;
      }
    }

    .search-input {
      width: 2.2rem;
      padding-right: .2rem;
      background: none;
      font-size: .14rem;
      color: #333333;
      line-height: .16rem;
      border: none;
      outline: none;
    }
  }

}
</style>
